﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;

using GDZJJGApp.ProgramePushWS;
using GDZJJGApp.IndexPushWS;

namespace GDZJJGApp
{
    public partial class Form1 : Form
    {

        private string unitCode = "613001",
                        unitName = "江门市",
                        startTime = "2016",
                        endTime = "2016",
                        vfCode = "AEMT7p8kL9";
        
        public Form1()
        {
            InitializeComponent();
        }
       
        private void button1_Click(object sender, EventArgs e)
        {
            ProgramePushWebService p = new ProgramePushWebService();
            object result = p.PushProgram(unitCode, unitName, startTime, endTime, 1, vfCode);
            richTextBox1.AppendText("----------PushProgram--------------\r\n");
            richTextBox1.AppendText(result.ToString() + "\r\n");

        }

        private void button2_Click(object sender, EventArgs e)
        {
            ProgramePushWebService p = new ProgramePushWebService();
            object result = p.PushProgramTotal(unitCode, unitName, startTime, endTime, vfCode);
            richTextBox1.AppendText("----------PushProgramTotal--------------\r\n");
            richTextBox1.AppendText(result.ToString() + "\r\n");
            

        }

        private void button3_Click(object sender, EventArgs e)
        {
            JdIndiWebService i = new JdIndiWebService();
            string result = i.PushIndexTotal(unitCode, unitName, startTime, endTime, vfCode);
            richTextBox1.AppendText("----------PushIndexTotal--------------\r\n");
            richTextBox1.AppendText(result + "\r\n");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            JdIndiWebService i = new JdIndiWebService();
            string result = i.PushIndex(unitCode, unitName, startTime, endTime, 1,vfCode);
            richTextBox1.AppendText("----------PushIndex--------------\r\n");
            richTextBox1.AppendText(result + "\r\n");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //接收文本数据
            Socket socket = null;
            MemoryStream memStream = null;
            string returnMsg = string.Empty;
            //与服务器建立连接
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress add = IPAddress.Parse("127.0.0.1");
            IPEndPoint endPt = new IPEndPoint(add, 1999);
            socket.Connect(endPt);
            //接收数据
            byte[] buffer = new byte[1024];
            int recCount = 0;
            memStream = new MemoryStream();
            //接收返回的字节流
            while ((recCount = socket.Receive(buffer)) > 0)
            {
                memStream.Write(buffer, 0, recCount);
            }
            Encoding encoding = Encoding.GetEncoding("GBK");
            returnMsg = encoding.GetString(memStream.GetBuffer(), 0, memStream.GetBuffer().Length);


        }


    }
}
